﻿
USE ERP;

DELIMITER GO

DROP PROCEDURE IF EXISTS procCompanyDML
GO

CREATE PROCEDURE procCompanyDML
(
     IN _Cmd TINYINT(0)
    ,IN _ID INT(10)
    ,IN _Code VARCHAR(50)
    ,IN _Name VARCHAR(120)
)
COMMENT 'Contains all necessary procedures to mnanage records for sys_COMPANY_M'
BEGIN
    IF _Cmd = 0 AND _ID = -1 THEN
        SELECT * FROM sys_COMPANY_M WHERE ID = 0;
    ELSEIF _Cmd = 0 AND _ID = 0 THEN
        SELECT * FROM sys_COMPANY_M;
    ELSEIF _Cmd = 0 AND _ID <> 0 THEN
        SELECT * FROM sys_COMPANY_M WHERE ID = _ID;
    ELSEIF _Cmd = 1 THEN
        INSERT INTO sys_COMPANY_M(Code ,Name)VALUES(_Code ,_Name);
        SELECT LAST_INSERT_ID() AS ID;
    ELSEIF _Cmd = 2 THEN
        UPDATE sys_COMPANY_M SET Code = _Code ,Name = _Name WHERE ID = _ID;
    ELSEIF _Cmd = 3 THEN
        DELETE FROM sys_COMPANY_M WhERE ID = _ID;
    END IF;
END;
GO

DELIMITER ;